import { IsString, IsNumber, IsOptional, Min, Max, IsEnum, IsDateString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { PaymentStatus } from '@/database/entities/payment-order.entity';

export class CreatePaymentOrderDto {
  @ApiProperty({ description: '订单金额', example: 100.50 })
  @IsNumber({ maxDecimalPlaces: 2 })
  @Min(0.01)
  @Max(999999.99)
  amount: number;

  @ApiProperty({ description: '支付方式', example: 'alipay', enum: ['alipay', 'wechat', 'bank'] })
  @IsString()
  @IsEnum(['alipay', 'wechat', 'bank'])
  paymentMethod: string;

  @ApiProperty({ description: '订单描述', required: false })
  @IsOptional()
  @IsString()
  description?: string;

  @ApiProperty({ description: '客户端IP', required: false })
  @IsOptional()
  @IsString()
  clientIp?: string;
}

export class UpdatePaymentOrderDto {
  @ApiProperty({ description: '订单状态', required: false })
  @IsOptional()
  @IsEnum(PaymentStatus)
  status?: PaymentStatus;

  @ApiProperty({ description: '第三方订单号', required: false })
  @IsOptional()
  @IsString()
  thirdPartyOrderNo?: string;

  @ApiProperty({ description: '失败原因', required: false })
  @IsOptional()
  @IsString()
  failReason?: string;
}

export class QueryPaymentOrdersDto {
  @ApiProperty({ description: '页码', required: false, default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  page?: number = 1;

  @ApiProperty({ description: '每页数量', required: false, default: 10 })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  @Max(100)
  pageSize?: number = 10;

  @ApiProperty({ description: '订单状态', required: false })
  @IsOptional()
  @IsEnum(PaymentStatus)
  status?: PaymentStatus;

  @ApiProperty({ description: '支付方式', required: false })
  @IsOptional()
  @IsString()
  paymentMethod?: string;

  @ApiProperty({ description: '开始日期', required: false })
  @IsOptional()
  @IsDateString()
  startDate?: string;

  @ApiProperty({ description: '结束日期', required: false })
  @IsOptional()
  @IsDateString()
  endDate?: string;

  @ApiProperty({ description: '关键词搜索', required: false })
  @IsOptional()
  @IsString()
  keyword?: string;
}

export class RefundOrderDto {
  @ApiProperty({ description: '退款原因', required: false })
  @IsOptional()
  @IsString()
  reason?: string;
}